package com.snda.lib.util;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

/**
 * 
 * @author zhangzhongqing
 * @param 屏幕相关的数据
 */
public class ScreenInfo {

	public Integer nHorizontalSize = 0; // 水平尺寸
	public Integer nVerticalSize = 0; // 垂直尺寸
	public Integer nColorBits = 0; //

	private Integer nWidthPixels = 0;
	private Integer nHeightPixels = 0;

	private static ScreenInfo screenInfo = null;

	public static ScreenInfo getInstance(Context appContext) {
		if (screenInfo == null) {
			screenInfo = new ScreenInfo();
			screenInfo.initValue(appContext);
		}

		return screenInfo;
	}

	private ScreenInfo() {
	}

	public void initValue(Context appContext) {
		if (appContext == null)
			return;

		WindowManager wm = (WindowManager) appContext
				.getSystemService(Context.WINDOW_SERVICE);
		if (wm == null)
			return;

		Display display = wm.getDefaultDisplay();
		if (display == null)
			return;

		nHorizontalSize = display.getWidth();
		nVerticalSize = display.getHeight();

		/* 引用android.util.DisplayMetrics */
		DisplayMetrics dm = new DisplayMetrics();
		display.getMetrics(dm);

		nWidthPixels = dm.widthPixels;
		nHeightPixels = dm.heightPixels;
	}

	public String getSizeString() {
		return nHorizontalSize + "x" + nVerticalSize;
	}

	// 宽度x高度
	public String getMetricsString() {
		return nWidthPixels + "x" + nHeightPixels;
	}
}
